<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>计算器</title>
</head>
<body>
	<?php 
		if(!empty($_POST)) {
			$v1 = $_POST['data1'];
			$v2 = $_POST['data2'];
			$v3 = $_POST['yunsuanfu'];
			if($v3 == "+") {
				$jieguo = $v1 + $v2;
			}
			if($v3 == "-") {
				$jieguo = $v1 - $v2;
			}
			if($v3 == "*") {
				$jieguo = $v1 * $v2;
			}
			if($v3 == "/") {
				if($v2 == 0){
					$jieguo = "分母不为“0”";
				} else {
					$jieguo = $v1 / $v2;
				}
			}
		} else {
			$jieguo = "";
			$v1 = "";
			$v2 = "";
			$v3 = "+";
		}
	 ?>
	 <!-- 
	 	表单中的说有数据都进行提交的，都必须进行对数据提交的值进行name值得定义。
	 -->
	<form action="./h1-jisuanqi.php" method="post">
		<input type="text" name="data1" value="<?php echo $v1; ?>">
		<select name="yunsuanfu">
			<option value="+">+</option>
			<option value="-" <?php if($v3 == "-"){echo 'selected="selected"'; } ?> >-</option>
			<option value="*" <?php if($v3 == "*"){echo 'selected="selected"'; } ?> >*</option>
			<option value="/" <?php if($v3 == "/"){echo 'selected="selected"'; } ?> >/</option>
		</select>
		<input type="text" name="data2" value="<?php echo $v2; ?>" />
		<input type="submit" name="" value="=">
		<input type="text" name="result" value="<?php echo $jieguo; ?>" />
	</form>
	
</body>
</html>